/*
  Applicast API Extension/Utility Library
  MemoPageScroller component

  (c) 2009 ILERRED, S.L.

  Applicast API Extension Library is freely
  distributable under the terms of an MIT-style license.
*/
var MemoPageScroller = Class.create({
  initialize: function(textNode, text, options) {
    this.options = {
      linesPerPage: 15
    };
    Object.extend(this.options, options || { });

    this.node = $(textNode);
    this.node.setStr(text);
    this.text = text;
    this.lines = this.node.getLines();
    this.pages = Math.ceil(this.lines / this.options.linesPerPage);
    this.currentPage = 0;

    if ( typeof this.updateScrollBars !== 'undefined' )
      this.updateScrollBars();
  },

  pageUp: function() {
    this.currentPage--;
    if ( this.currentPage >= 0 )
      this.node.pageUp();
    else
      this.currentPage = 0;

    if ( typeof this.updateScrollBars !== 'undefined' )
      this.updateScrollBars();
  },

  pageDown: function() {
    this.currentPage++;
    if ( this.currentPage <= this.pages - 1 )
      this.node.pageDown();
    else
      this.currentPage = this.pages - 1;

    if ( typeof this.updateScrollBars !== 'undefined' )
      this.updateScrollBars();
  }
});
